
  Page({
    data: {shop:[],shopmore:[],arr:[],uid:'',id:'',
        latitude: '',
        longitude: '',
        scale:16,
        flagmap:false,
        markers: [{
            id:1,
            markerId: 1,
            name:2,
            latitude: '',
            longitude: '',
            title: 'markerId: 1',
            width:15,
            height:30,
            zIndex: 100,
            iconPath: '../../img/location.png',  
            callout: {
                display: 'BYCLICK',
                content: '我的位置',
                color: '#000',
                fontSize: '14',
                borderRadius: 50,
                bgColor: '#5B9FFF',
                padding: 2,
                textAlign: 'center'
            }
        }]
    },
    onLoad(){
     
     

    },
    onShow(){
      this.getLocation()
      console.log(this.data.markers);
      console.log(this.data.flagmap);
      let uid=wx.getStorageSync('uid')?wx.getStorageSync('uid'):''
      this.setData({uid})
      if(uid==''){
        wx.navigateTo({
          url: '/pages/mine/loginuser/loginuser?id='+this.data.id,
        })
      }
     
     
      
      
    },
    getLocation(){
      const that=this
      wx.getSetting({
        success:(res)=> {
          console.log(res);
          if (!res.authSetting['scope.userLocation']) {
            wx.authorize({
              scope: 'scope.userLocation',
              success :()=> {
                 //获取 位置
          wx.getLocation({
         type: 'gcj02',
         altitude:true,
        
         success: (result)=>{
        console.log(result);
        let longitude="markers[0].longitude"
        let latitude="markers[0].latitude"
        that.setData({
        latitude:result.latitude,
        longitude:result.longitude,
        [longitude]:result.longitude,
        [latitude]:result.latitude

        })
        this.getshoplist(result.longitude,result.latitude)
      }
     
     
    });
                
              }
            })
          }else{ 
            //获取位置
            wx.getLocation({
           type:'gcj02',
         success: (result)=>{
           console.log(result);
           let longitude="markers[0].longitude"
           let latitude="markers[0].latitude"
           that.setData({
           latitude:result.latitude,
           longitude:result.longitude,
           [longitude]:result.longitude,
           [latitude]:result.latitude

           })
           this.getshoplist(result.longitude,result.latitude)
         }
        
        
       })}
        }
      })
     
  },
  //点击标注获取商家信息
  bindmarkertap(e){
    this.setData({arr:[]})
    let shopobj= this.data.shopmore.filter((item,index)=>{
         return (e.markerId==this.data.shopmore[index].id)
       })
       this.setData({
         shop:shopobj
       })
       console.log(shopobj);
       
       
       
     
   
  },
  //获取周别店铺
  getshoplist(lng,lat){
   /* const lng=this.data.longitude
    const lat=this.data.latitude*/
   
    
    var that=this
    var spec1
    wx.request({
      url: 'https://zujieba.com/api/store/list_store.html',
     data:{distance:1,lng:lng,lat:lat},
      success:(res)=>{
       console.log(res,lng,lat);
       
    
        wx.request({
          url: 'https://zujieba.com/Api/storeadminstore/type.html',
          
          method:'POST',
          success:(res1)=>{
            console.log(res1);
            spec1=res1.data.data
          
            const arr=[]
            let shop= res.data.data
            console.log(shop);
            
            
            shop.forEach((item)=>{
              item.mune1=[]
              item.long=(item.long/1000).toFixed(1)
              item.mune.forEach((item1,index)=>{
                
                
                spec1.forEach((item2)=>{
                  
                  
                  if(item2.id==item1&&(item2.title=='黑白'||item2.title=='彩色')){
                       
                       item.mune1.push(item2.title)
                 
                       
                       
                    
                  }
                })
              })
            })
            let obj1=shop[0]
            arr.push(obj1)
            console.log(arr);
            
            that.setData({
              shop:arr,
              shopmore:shop
            })
            
             
            
           
            let array=[]
            
            for (var  i=0;i<shop.length;i++){
             var longitude=shop[i].lng
             var latitude=shop[i].lat
             var title=shop[i].title
             var id=shop[i].id
             var zIndex=100
             var city=shop[i].city
              var width=15
              var height=30
              var long=shop[i].long
              var markerId=shop[i].id
              var iconPath='../../img/location1.png'
             var obj={longitude,latitude,title,id,width,height,markerId,iconPath,zIndex,long,city}
             array.push(obj)
            }
            let markersobj=that.data.markers[0]
            let markers=[markersobj]
            const concat=markers.concat(array)
           that.setData({
             markers:concat,
             
           })
           



          }
        })
       
      
      
       
       

       
     }
   })

  },
  //店铺详情
  store_xq:function(e){
    console.log(e);
    
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/near/store_xq/store_xq?near_id='+id+'&statu=index1',
      
    })
  },
  navnear(e){
    wx.navigateTo({
      url: '/pages/index/near/near?statu='+e.currentTarget.dataset.statu
    })
  },
  mapclick(e){
    console.log(e);
    console.log(this.data.shop);
    let lat=e.currentTarget.dataset.latitude
    let lng=e.currentTarget.dataset.longitude
    console.log();
    
    
    wx.openLocation({
      name:e.currentTarget.dataset.title,
      latitude: Number(lat),
      longitude:Number(lng),
      scale:16
    })
    
  },
  makephone(e){
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone,
      success:(res)=>{
        console.log(res);
        
      },
      fail:(res)=>{
        console.log(res);
        
      }
    })
},

onHide(){
 
  
},
getshareshop1(){
  
  
  
  wx.request({
    url: 'https://zujieba.com/Api/storeadminstore/type.html',
    
    method:'POST',
    success:(res)=>{
      console.log(res);
    }
  })
},
 
      
   
});








